<?php
namespace app\index\controller;

class viewController extends \app\base\controller\BaseController
{
    public function index(){
       $id=$this->arg("id");
       if(!is_numeric($id)){
        exit("error");
       }

       $where[] = "  `id` ={$id} ";
       $view = obj("api/Apidata")->Data_Select("goods", $where);
	if($view['content']=="" || $view['content']==null){
	   $url=url($route='go/to/url/id=<id>', $params=array('id'=>$id));	
	   $this->redirect($url);
      exit;	   
	 }
	   
       $this->view=$view;
	   
       //商城推荐
       //$mall= obj("index/global", "controller")->type("y", $view['mallb'], "mall", "id");
       //$this->mall=$mall;
	   
	   //$sql = "select * from `{pre}category` where `mallType`=0 and ID in (select min(ID) from `{pre}category` group by `mallName`)";
		//$this->mall= obj('api/ApiData')->thisquery($sql);

       //判断商品是国内还是海淘
       if($view['mallType']=="0" ){
       	

       	 //国内最热点击榜
        $where_hot[]="`mallType` = '0'";
        $hot=obj("api/Apidata")->Data_Select("goods",$where_hot,"`view` DESC LIMIT 0 , 10");
        $this->hot=$hot;

        //推荐相关分类的商品
        $twhere[]="  `mallType` =  '0'   ";

         //商城推荐
        $malltwhere[]="  `mallType` = '0' AND  `mallName` ='{$view['mallName']}'";

       }else{
       

        //海淘最热点击榜
        $where_hot[]="`mallType` =  '1'";
        $hot=obj("api/Apidata")->Data_Select("goods",$where_hot,"`view` DESC LIMIT 0 , 10");
        $this->hot=$hot;

        //推荐相关分类的商品
        $twhere[]="  `mallType` =  '1' ";
        
         //商城推荐
         $malltwhere[]="  `mallType` =  '1' AND  `mallName` ='{$view['mallName']}'";
       }
      
        $this->tret= obj("api/Apidata")->Data_Select("goods", $twhere,"rand() LIMIT 0 , 5");

       $this->malltret= obj("api/Apidata")->Data_Select("goods", $malltwhere,"rand() LIMIT 0 , 5");

       $this->display();

    }


}